import { Sqlit3DB } from "../lib/TeSqlite3";
import { readFileSync, writeFileSync } from "fs";
import { join } from 'path';
import { createHash } from 'crypto'

Sqlit3DB.registTable('pic2', [{
    name: 'name',
    type: 'string',
    isPrimary: true,
}, {
    name: 'name2',
    type: 'string'
}])

Sqlit3DB.registTable('tinypic', {
    "tinymd5": {
        "type": "string",
        "isPrimary": true
    },
    "name": "string",
    "srcmd5": "string",
    "time": "number",
    "pic": "Buffer"
})

Sqlit3DB.inst.init('./sqlite3_path1.db').then(async function () {
    await Sqlit3DB.inst.insertInfo('pic2', { name: 'chenkai1', name2: "123" }).catch(function (e) { });
    // Sqlit3DB.inst.selectInfo('pic2', { name2: '123' },function(err,rows){
    //     console.log(rows)
    // });

    // let imgName = 'C:\\Users\\boy_9\\Documents\\Tencent Files\\659545609\\FileRecv\\logo_duidui.png';
    // let img = readFileSync(imgName).toString('base64');
    let name = '2019-09-02.png';
    // let img = readFileSync(join(process.cwd(), 'test', name))
    // let md5 = createHash('md5').update(img).digest('hex');
    await Sqlit3DB.inst.updateInfo('pic2', {
        name: 'chenkai1',
    }, {
        name2: 'aaaa',
    }).catch(e => { console.warn(e) });
    let row = await Sqlit3DB.inst.selectInfo('pic2', {
        name: 'chenkai1'
    })

    for (let i = 0; i < row.length; i++) {
        // writeFileSync(join(process.cwd(), 'test', row[i].tinymd5 + row[i].name), row[i].pic);
        console.log(row[i].name2.toString());
    }
})

